package controller;

import core.BaseServlet;
import service.WorkerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "LoginServlet", urlPatterns = "/login")
public class LoginServlet extends BaseServlet {
    private WorkerService workerService = new WorkerService();

    /**
     * 登录页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void loginPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/login.jsp").forward(request, response);
    }

    /**
     * 登录方法
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void loginDo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        workerService.login(request, response);
    }


    /**
     * 根据登录名获取员工的登录错误次数
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void getLoginerrorTimes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        workerService.getLoginerrorTimes(request, response);
    }

    /**
     * 根据电话号码发送验证码
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void sendCodeByForgetWorkerPhone(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        workerService.sendCodeByForgetWorkerPhone(request, response);
    }


    /**
     * 根据验证码获取密码
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void resetPasswordByForgetWorkerPhone(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        workerService.resetPasswordByForgetWorkerPhone(request, response);
    }


}
